import 'package:flutter_frame/app/modules/auth/auth/view.dart';
import 'package:flutter_frame/app/modules/auth/login/view.dart';
import 'package:flutter_frame/app/modules/home/biometric_identification/biometric_identification_view.dart';
import 'package:flutter_frame/app/modules/home/canvas/canvas_rabbit/canvas_rabbit_view.dart';
import 'package:flutter_frame/app/modules/home/home/view.dart';
import 'package:flutter_frame/router/app_auth_middleware.dart';
import 'package:get/get.dart';

part 'app_routes.dart';

abstract class AppPages {
  AppPages._();

  /// 入口
  static const String initial = AppRoutes.home;

  static final routes = _generateRoutes();

  static List<GetPage<dynamic>> _generateRoutes() {
    final result = <GetPage<dynamic>>[];
    result.addAll(_generateAuthRoutes());
    result.addAll(_generateHomeRoutes());
    result.addAll(_generateProfileRoutes());
    return result;
  }

  /// 构建页面
  ///
  /// [needAuth] 表示是否需要登录认证才可访问
  static GetPage<dynamic> generatePage({
    required String name,
    required GetPageBuilder page,
    bool needAuth = false,
    String? title,
    Transition? transition,
    List<GetMiddleware>? middlewares,
  }) {
    final middlewareList = <GetMiddleware>[];

    if (middlewares?.isNotEmpty == true) {
      middlewareList.addAll(middlewareList);
    }

    if (needAuth) {
      middlewareList.add(AppAuthMiddleWare());
    }

    return GetPage(
      name: name,
      page: page,
      title: title,
      transition: transition ?? Transition.cupertino,
      middlewares: middlewareList,
    );
  }

  /// auth相关
  static List<GetPage> _generateAuthRoutes() {
    return [
      generatePage(
        name: AppRoutes.auth,
        page: AuthPage.new,
        transition: Transition.fadeIn,
      ),
      generatePage(
        name: AppRoutes.authLogin,
        page: LoginPage.new,
      ),
    ];
  }

  /// 首页
  static List<GetPage> _generateHomeRoutes() {
    return [
      generatePage(
        name: AppRoutes.home,
        page: HomePage.new,
      ),

      generatePage(
        name: AppRoutes.biometrics,
        page: BiometricIdentificationWidget.new,
      ),
      generatePage(
        name: AppRoutes.canvasRabbitWidget,
        page: CanvasRabbitWidget.new,
      ),

    ];
  }

  /// 个人中心
  static List<GetPage> _generateProfileRoutes() {
    return [
      // generatePage(
      //   name: AppRoutes.profile,
      //   page: ProfilePage.new,
      // ),
    ];
  }


}
